The use of GOTO
in general is arguable. However, when used within loops, GOTO
statements are even more evil, and they can
often be replaced by other constructs.
Noncompliant code example
DECLARE
i PLS_INTEGER := 0;
BEGIN
LOOP
IF i = 3 THEN
GOTO loopEnd; -- Noncompliant
END IF;
DBMS_OUTPUT.PUT_LINE('i = ' || i);
i := i + 1;
END LOOP;
<<loopEnd>>
DBMS_OUTPUT.PUT_LINE('Loop end');
END;
/
Compliant solution
DECLARE
i PLS_INTEGER := 0;
BEGIN
LOOP
EXIT WHEN i = 3; -- Compliant
DBMS_OUTPUT.PUT_LINE('i = ' || i);
i := i + 1;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Loop end');
END;
/